using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using MULENetworking;

namespace MainGame
{
    /*This Form is the main form where all the game is going to be displayed at.
     * This form will call an Engine Class which i the main engine for the game.
     * This form will also handle any mouse events and send them to the Engine to 
     * be processed.*/

    public partial class MainGame : Form
    {
        private Stopwatch timer = new Stopwatch();
        private double lastTime;
        private long frameCounter;
        private Engine engine;
        private string netconnect;




        public MainGame(string serverInfo, int player)
        {
            //Setup the form
            InitializeComponent();
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true);
            netconnect = serverInfo;
            //Startup the game state
            engine = new Engine(ClientSize, netconnect, player);

            initialize();
        }

        private void initialize()
        {
            engine.Initialize();

            //Initialise and start the timer
            lastTime = 0.0;
            timer.Reset();
            timer.Start();
            this.Invalidate();

        }

        private void MainGame_Paint(object sender, PaintEventArgs e)
        {
            //Work out how long since we were last here in seconds
            double gameTime = timer.ElapsedMilliseconds / 1000.0;
            double elapsedTime = gameTime - lastTime;
            lastTime = gameTime;
            frameCounter++;


            //Perform any animation and updates
            //Engine.Update(gameTime, elapsedTime);


            //Draw everything
            
            engine.Draw(e.Graphics);


            //Force the next Paint()
            this.Invalidate();

        }

        private void MainGame_MouseClick(object sender, MouseEventArgs e)
        {
            engine.MouseClick(e.Location);
        }

        private void MainGame_Load(object sender, EventArgs e)
        {

        }

        private void MainGame_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            engine.MouseDoubleClick(e.Location);
        }






    }
}